import django_filters

from vouchers.models import AliDiscountCouponInfo, CustomizeActivity, UpdateStockUsableMerchant
from users.models import CustomerUserVice, Level
from merchants.models import Merchant
from orders.models import OrderInfo, AfterSaleReason, AfterSaleApplicationForm, Express, OrderGoods
from goods.models import Goods
from newyears.models import NewYearsShoppingFestivalElectProductLike
from alipaynfc.models import *


class AliDiscountCouponInfoFilter(django_filters.rest_framework.FilterSet):
    '''支付宝活动过滤'''

    status = django_filters.BaseInFilter(field_name='status', lookup_expr='in')

    class Meta:
        model = AliDiscountCouponInfo
        fields = ('status', )


class CustomizeActivityFilter(django_filters.rest_framework.FilterSet):
    '''支付宝活动过滤'''

    activity_type = django_filters.BaseInFilter(field_name='activity_type', lookup_expr='in')

    class Meta:
        model = CustomizeActivity
        fields = ('activity_type', )


class CustomerUserViceFilter(django_filters.rest_framework.FilterSet):
    '''支付宝活动过滤'''

    inviter_time_begin = django_filters.DateTimeFilter(field_name="inviter_time__date", lookup_expr='gte')
    inviter_time_end = django_filters.DateTimeFilter(field_name="inviter_time__date", lookup_expr='lte')

    class Meta:
        model = CustomerUserVice
        fields = ('inviter_time_begin', 'inviter_time_end')


class MerchantFilter(django_filters.rest_framework.FilterSet):
    '''商户过滤'''

    category_id = django_filters.BaseInFilter(field_name='goods__category_id', lookup_expr='in')
    alidiscountcoupon_id = django_filters.BaseInFilter(field_name='alidiscountcouponmerchant__alidiscountcoupon_id', lookup_expr='in')

    class Meta:
        model = Merchant
        fields = ('category_id',)


class LevelFilter(django_filters.rest_framework.FilterSet):
    '''层级过滤'''

    city_id = django_filters.BaseInFilter(field_name='city_id', lookup_expr='in')
    prov_id = django_filters.BaseInFilter(field_name='prov_id', lookup_expr='in')
    # goods_id = django_filters.BaseInFilter(field_name='launchedgoods__goods_id', lookup_expr='in')

    class Meta:
        model = Level
        fields = ('prov_id', 'city_id')


class OrderInfoFilter(django_filters.rest_framework.FilterSet):
    '''订单过滤'''

    state = django_filters.BaseInFilter(field_name='state', lookup_expr='in')
    merchant_id = django_filters.BaseInFilter(field_name='merchant_id', lookup_expr='in')
    order_species = django_filters.BaseInFilter(field_name='order_species', lookup_expr='in')

    class Meta:
        model = OrderInfo
        fields = ('state', 'merchant_id', 'order_species')


class GoodsFilter(django_filters.rest_framework.FilterSet):
    '''商品过滤'''

    alidiscountcoupon_id = django_filters.BaseInFilter(field_name='alidiscountcoupongoodsavailable__alidiscountcoupon_id', lookup_expr='in')
    # level_id = django_filters.BaseInFilter(field_name='launchedgoods__level_id', lookup_expr='in')
    merchant_id = django_filters.BaseInFilter(field_name='merchant_id', lookup_expr='in')
    is_group = django_filters.BaseInFilter(field_name='is_group', lookup_expr='in')
    price_min = django_filters.NumberFilter(field_name="price", lookup_expr='gte')
    price_max = django_filters.NumberFilter(field_name="price", lookup_expr='lte')

    class Meta:
        model = Goods
        fields = ('alidiscountcoupon_id', 'merchant_id', 'price_min', 'price_max', 'is_group')


class NewYearsShoppingFestivalElectProductLikeFilter(django_filters.rest_framework.FilterSet):

    elect_id = django_filters.BaseInFilter(field_name='product__elect_id', lookup_expr='in')

    class Meta:
        model = NewYearsShoppingFestivalElectProductLike
        fields = ('elect_id', )


class AfterSaleReasonFilter(django_filters.rest_framework.FilterSet):

    reason_type = django_filters.BaseInFilter(field_name='reason_type', lookup_expr='in')

    class Meta:
        model = AfterSaleReason
        fields = ('reason_type', )


class AfterSaleApplicationFormFilter(django_filters.rest_framework.FilterSet):

    form_status = django_filters.BaseInFilter(field_name='form_status', lookup_expr='in')

    class Meta:
        model = AfterSaleApplicationForm
        fields = ('form_status', )


class ExpressFilter(django_filters.rest_framework.FilterSet):

    deliverystatus = django_filters.BaseInFilter(field_name='deliverystatus', lookup_expr='in')
    # nature = django_filters.BaseInFilter(field_name='nature', lookup_expr='in')
    order_id = django_filters.BaseInFilter(field_name='expressorderrelevance__order_id', lookup_expr='in')
    create_time_begin = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='gte')
    create_time_end = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='lte')
    sign_time_begin = django_filters.DateTimeFilter(field_name="sign_time__date", lookup_expr='gte')
    sign_time_end = django_filters.DateTimeFilter(field_name="sign_time__date", lookup_expr='lte')

    class Meta:
        model = Express
        fields = ('deliverystatus', 'create_time_begin', 'create_time_end', 'sign_time_begin', 'sign_time_end', 'order_id')


class OrderGoodsFilter(django_filters.rest_framework.FilterSet):

    is_commented = django_filters.BaseInFilter(field_name='is_commented', lookup_expr='in')
    goods_id = django_filters.BaseInFilter(field_name='goods_id', lookup_expr='in')

    class Meta:
        model = OrderGoods
        fields = ('is_commented', 'goods_id')


class NFCDeviceBountyQuestScheduleFilter(django_filters.rest_framework.FilterSet):

    quest_status = django_filters.BaseInFilter(field_name='quest_status', lookup_expr='in')

    class Meta:
        model = NFCDeviceBountyQuestSchedule
        fields = ('quest_status', )